//
//  GundongViewController.swift
//  neusoft food
//
//  Created by 炸毛 on 2017/9/21.
//  Copyright © 2017年 炸毛. All rights reserved.
//

import UIKit

class GundongViewController: UIViewController,UIScrollViewDelegate{
    var numOfPages = 3
    override func viewDidLoad() {
        super.viewDidLoad()
      let frame = self.view.bounds
        //scrollView 初始化
        let scrollView=UIScrollView()
        scrollView.frame=self.view.bounds
        scrollView.delegate=self
        //设置横向滚动内容为3个页面的宽度
        scrollView.contentSize=CGSize(width:frame.size.width*CGFloat(numOfPages),height:frame.size.height)
        scrollView.isPagingEnabled=true
        scrollView.showsHorizontalScrollIndicator=false
        scrollView.showsVerticalScrollIndicator=false
        scrollView.scrollsToTop=false
        
        for i in 0..<numOfPages{
            let imgfile="\(Int(i+1)).png"
            print(imgfile)
            let image = UIImage(named:"\(imgfile)")
            let imgView = UIImageView(image: image)
            imgView.frame=CGRect(x:
                frame.size.width*CGFloat(i),y:CGFloat(0),width:
                frame.size.width,height: frame.size.height)
            scrollView.addSubview(imgView)
            }
        scrollView.contentOffset=CGPoint.zero
        self.view.addSubview(scrollView)
        
    }
    
    func scrollViewDidScroll(_ scrollView: UIScrollView)
    {
      print("scrolled:\(scrollView.contentOffset)")
        let thirdh = CGFloat(numOfPages-1)*self.view.bounds.size.width
        if(scrollView.contentOffset.x > thirdh)
        {
            let mainStoryboard = UIStoryboard(name:"Main",bundle:nil)
            let viewController: ViewController = mainStoryboard.instantiateViewController(withIdentifier:"mainstoryboard") as!ViewController
            self.present(viewController,animated: true,completion: nil)
            
        
        }
    
    
    
    
    
    
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
